﻿/*文件注释
 * ===============================================================================
 * 说明：
 * 作者：曾永佑
 * 版本：V1.0
 * 创建日期：2013-03-10
 * 完成日期： 
 * 修改纪录：  
 * ===============================================================================
 */  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web.Configuration;
using SRF.Security.Principal;

namespace SRF.Security.Principal
{
    public class MembershipFactory
    {
        public static MembershipProvider Provider
        {
            get
            {
                MembershipProvider provider;
                MembershipSection section = (MembershipSection)ConfigurationManager.GetSection("MembershipProvider");
                if (section != null)
                {
                    MembershipProviderCollection providers = new MembershipProviderCollection();
                    ProvidersHelper.InstantiateProviders(section.Providers, providers, typeof(MembershipProvider));
                    if (!string.IsNullOrEmpty(section.DefaultProvider))
                    {
                        provider = providers[section.DefaultProvider];
                        if (provider == null)
                            throw new System.Configuration.Provider.ProviderException("没有找到默认的 MembershipProvider");
                    }
                    else
                    {
                        provider = new MembershipProvider();
                    }
                }
                else
                {
                    throw new ConfigurationErrorsException();
                }

                return provider;
            }
        }
    }
}